
#include <util/msg.h>
#include <util/common_macros.h>

#include "../../matrix/matrix.h"

void imp_image_or(ImpMatrix * A, ImpMatrix * B, ImpMatrix ** Or) {

	_return_if_fail(A && B);

	int rows, columns;
	int r, c, _r, i;

	real * a, * b, * or;

	rows = A->rows;
	columns = B->columns;
	
	a = A->data;
	b = B->data;

	if (*Or == NULL) (*Or) = imp_matrix_new(rows, columns);
	or = (*Or)->data;

	for (r = 0, _r = r * columns; r < rows; r++, _r += columns) {
		for (c = 0; c < columns; c++) {
			i = _r + c;
			or[i] = MAX(a[i], b[i]);
		}
	}
}

void imp_image_and(ImpMatrix * A, ImpMatrix * B, ImpMatrix ** And) {

	_return_if_fail(A && B);

	int rows, columns;
	int r, c, _r, i;

	real * a, * b, * and;

	rows = A->rows;
	columns = B->columns;

	a = A->data;
	b = B->data;
	
	if (*And == NULL) (*And) = imp_matrix_new(rows, columns);
	and = (*And)->data;

	for (r = 0, _r = r * columns; r < rows; r++, _r += columns) {
		for (c = 0; c < columns; c++) {
			i = _r + c;
			and[i] = MIN(a[i], b[i]);
		}
	}
}
